﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace winformDoDragDrop
{
    public partial class SimpleForm2 : Form
    {
        public SimpleForm2()
        {
            InitializeComponent();
        }

        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            // 开始拖拽操作，将按钮的文本作为拖拽数据
            textBox1.DoDragDrop(button1.Text, DragDropEffects.Copy | DragDropEffects.Link);
        }

        private void textBox1_DragEnter(object sender, DragEventArgs e)
        {
            // 检查拖拽的数据是否为文本格式
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                e.Effect = DragDropEffects.Link; // 设置拖放效果为复制
            }
            else
            {
                e.Effect = DragDropEffects.None; // 不允许拖放
            }
        }

        private void textBox1_DragDrop(object sender, DragEventArgs e)
        {
            // 获取拖拽的数据并设置到目标控件中
            
            textBox1.Text = e.Data.GetData(DataFormats.Text).ToString();
        }
    }
}
